package com.example.arithmeticleetcode.leetcode.September;

import java.math.BigDecimal;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-09-02 10:27
 **/
public class Demo02 {

    public static void main(String[] args) {
        int[] nums1 = {1, -2, -3, 4};
        int[] nums2 = {0, 1, -2, -3, -4};
        int[] nums3 = {-1, -2, -3, 0, 1};
        int[] nums4 = {-1, 2};
        int[] nums5 = {1, 2, 3, 5, -6, 4, 0, 10};
        int[] nums6 = {1000000000,1000000000};
        System.out.println(getMaxLen(nums1)); //4
        System.out.println(getMaxLen(nums2)); //3
        System.out.println(getMaxLen(nums3)); //2
        System.out.println(getMaxLen(nums4)); //1
        System.out.println(getMaxLen(nums5)); //4
        System.out.println(getMaxLen(nums6)); //2


    }


    public static int getMaxLen(int[] nums) {
        int length = nums.length;
        int curLength = length;
        while (0 <= curLength) {

            for (int i = 0; i <= length - curLength; i++) {
               int count = 0;
               boolean zeroFlag = true;
                for (int j = i, jLength = i + curLength; j < jLength; j++) {
                    if (nums[j] < 0) {
                        count ++;
                    }
                    if (nums[j] == 0) {
                        zeroFlag = false;
                    }
                }
                if (count % 2 == 0 && zeroFlag) {
                    return curLength;
                }
            }
            curLength--;
        }

        return 0;
    }
}
